/*
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
 *
 * Copyright (c) 2013-2014 sagyf Yang. The Four Group.
 */
define(['adminapp'], function ($app) {
    $app.navactive('exchage_record');

    var $listtable = $app.listtable({
        'sAjaxSource'  : g.ctx + "admin/gift/exchange/list",
        'aoColumns'    : [
            $app.autono,
            {'mDataProp': 'exchange_time' },
            {'mDataProp': 'code' },
            {'mDataProp': 'name' },
            {'mDataProp': 'gintegral' },
            {'mDataProp': 'mname' },
            {'mDataProp': 'card_no' },
            {'mDataProp': 'phone' },
            {'mDataProp': 'voucher' },
            {'mDataProp': 'receive_time' }
        ],
        'fnServerParams': function (aoData) {
            var sd = $('#search_form').serializeJSON();
            $.each(sd, function (name, val) {
                aoData.push({"name": name, "value": val});
            });
        },
        'fnRowCallback': function (nRow, aData, iDisplayIndex) {
            var oSettings = this.fnSettings();
            $("td:eq(0)", nRow).html(oSettings._iDisplayStart + iDisplayIndex + 1);
            return nRow;
        },
        'aoColumnDefs' : [
            {
                'aTargets': [9],
                'mData'   : null,
                'mRender' : function (data, type, full) {
                    return full['receive_time'] ? '未领取' : full['receive_time'];
                }
            }
        ]
    }, 'exchange-list');

    var $searchBtn = $('#search_btn');
    $searchBtn.removeAttr('disabled');

    $searchBtn.on('click', function (e) {
        e.preventDefault();
        $listtable.fnReloadAjax();
    });
});

